package tianwang.biz.stat;

import java.util.ArrayList;

import tianwang.model.AticleModel;
import tianwang.model.CAStyle;
import tianwang.services.collect.CollectResult;
import tianwang.services.collect.Collecter;

/**
 *  平均句长
 * 
 * @author tian
 *
 */
public class SentenceAverageLength implements Collecter<CollectResult> {
	private final String name = CAStyle.AVERAGE_SENTENCE_LENGTH;
	
	
	@Override
	public CollectResult collect(Object material) throws Exception {
		AticleModel model = (AticleModel) material;
		ArrayList<ArrayList<String>> list = model.getPunctuatorWords();
		
		int len = list.size();
		int rlen = len;
		int slen = 0;
		int tmp = 0;
		for(int i = 0; i < len; i++){
			tmp = list.get(i).size();
			if(tmp == 0){
				rlen --;
				continue;
			}
				
			slen += tmp;
		}
		
		final float re = (float)slen/(float)rlen;
		
		return new CollectResult(){
			public Object pump(){
				return (int)re;
			}

			@Override
			public String getName() {
				return name;
			}
		};
	}

}
